﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="VoucherOutDetail.aspx.cs"
    Inherits="SalesManagement.Modules.Sales.VoucherOutDetail" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .red-text
        {
            color: red;
            font-size: large;
        }
        .x-grid3-cell-inner
        {
            font-family: "segoe ui" ,tahoma, arial, sans-serif;
        }
        .x-grid-group-hd div
        {
            font-family: "segoe ui" ,tahoma, arial, sans-serif;
        }
        .x-grid3-hd-inner
        {
            font-family: "segoe ui" ,tahoma, arial, sans-serif;
            font-size: 12px;
        }
        .x-grid3-body .x-grid3-td-Cost
        {
            background-color: #f1f2f4;
        }
        .x-grid3-summary-row .x-grid3-td-Cost
        {
            background-color: #e1e2e4;
        }
        .total-field
        {
            background-color: #fff;
            font-weight: bold !important;
            color: #000;
            border: solid 1px silver;
            padding: 1px;
            margin-right: 1px;
            text-align: right;
        }
        .search-item
        {
            font: normal 11px tahoma, arial, helvetica, sans-serif;
            padding: 3px 10px 3px 10px;
            border: 1px solid #fff;
            border-bottom: 1px solid #eeeeee;
            white-space: normal;
            color: #555;
        }
        .search-item h3
        {
            display: block;
            font: inherit;
            font-weight: bold;
            color: #222;
        }
        .search-item h3 span
        {
            float: right;
            font-weight: normal;
            margin: 0 0 5px 5px;
            width: 100px;
            display: block;
            clear: none;
        }
    </style>

    <script src="/Javascript/Global.js" type="text/javascript"></script>

    <script src="/Javascript/VoucherDetail.js" type="text/javascript"></script>

    <script language="javascript" type="text/javascript">

        function DocumentReady() {
            DirectMethod.DocumentReady({
                success: function() {
                    dfVoucherDate.focus();
                    if (hdVoucherId.getValue() == '')
                        AddOneRecord();
                },
                fulture: function() {

                }
            });
        }
        function Customer_Change(combo, record, index) {
            if (record.data.ObjectId > 0) {
                txtTaxCode.setValue(record.data.TaxCode);
                txtAddress.setValue(record.data.Address);
                DirectMethod.BindingQuotation(record.data.ObjectId);
                AddOneRecord();
            }

        }
        function AddOneRecord() {
            stDetail.clearData();
            for (var i = 0; i < 1; i++) {
                var newIndex = grDetail.addRecord({});
                var record = grDetail.store.getAt(newIndex);
                record.commit();
            }
        }
        function SaveVoucher() {
            if (!CheckBeforSaveVoucher())
                return;
            DirectMethod.SaveVoucher();
            //                success: function(status) {
            //                    if (status) {
            //                        //btnNew.setDisabled(false);
            //                        //vnMessageBox('Thông báo !', 'Lưu thành công', Ext.MessageBox.OK, 'txtVoucherNo.focus(true, 10);', Ext.MessageBox.INFO, 1);
            //                    }
            //                }
            //);

        }
        function CheckBeforSaveVoucher() {
            return true;
        }
        function BeforeEdit(cell) {
            var voucherId = hdVoucherId.getValue();
            if (voucherId == "" || voucherId <= 0) {
                SaveVoucher();
                return false;
            }
            countQuotation = stQuotation.getCount();
            if (countQuotation <= 0) {
                return false;
            }
            row = cell.row;
            column = cell.column;
            record = cell.record;

            if (column == 0) {
                record.set('ProductId', '');
                record.set('ProductCode', '');
                record.set('ProductName', '');
                return true;
            }
            if (record.data.ProductId == '') {
                record.set('ProductId', '');
                record.set('ProductCode', '');
                record.set('ProductName', '');
                record.set('UnitId', '');
                record.set('UnitPrice', '');
                record.set('Quantity', '');
                record.set('WarehouseId', '');
                record.set('VATPercent', '');
                record.set('VATAmount', '');
                record.set('DiscountPercent', '');
                record.set('DiscountAmount', '');
                record.set('Amount', '');
                record.set('TotalAmount', '');
                StartEdit_Grid(cell.grid, row, 0);
                return false;
            }
        }
        //        function afterEditProduct(el, a, b, c, e) {
        //            if (el.record.data.ProductId == '') {
        //                StartEdit_Grid(el.grid, el.column, e.row);
        //            }


        //            var Record = grDetail.selModel.selections.items[0];
        //        }
        //        function SpecialKey(el, a, b, c, e) {
        //            if (a.getCharCode() == 9 && el.lastSelectionText == "") {
        //                StartEdit_Grid(grDetail, 0, 0);
        //                a.stopEvent();
        //            }
        //            //var Record = grDetail.selModel.selections.items[0];
        //        }
        //        function beforeEdit() {
        //            var Record = grDetail.selModel.selections.items[0];
        //            Record.set('ProductId', '');
        //            Record.set('ProductCode', '');
        //            Record.set('ProductName', '');
        //        }

        function SelectItem(combo, record, index) {

            var Record = grDetail.selModel.selections.items[0];
            if (record == undefined || record == null) {
                Record.set('ProductId', '');
                Record.set('ProductCode', '');
                Record.set('ProductName', '');
                Record.set('UnitId', '');
                Record.set('UnitPrice', '');
                Record.set('Quantity', '');
                Record.set('WarehouseId', '');
                Record.commit();
            }
            Record.set('ProductId', record.data.ProductId);
            Record.set('ProductCode', record.data.ProductCode);
            Record.set('ProductName', record.data.ProductName);
            Record.set('UnitId', record.data.InputUnit);
            Record.set('UnitPrice', record.data.InputPrice);
            var QuanTity = Record.get('Quantity');
            if (QuanTity <= 0)
                QuanTity = 1;
            Record.set('Quantity', QuanTity);

            var VATPercent = Record.get('VATPercent');
            if (VATPercent <= 0)
                VATPercent = 0;
            Record.set('VATPercent', VATPercent);
            var DiscountPercent = Record.get('DiscountPercent');
            if (DiscountPercent <= 0)
                DiscountPercent = 0;
            Record.set('DiscountPercent', DiscountPercent);
            Record.set('WarehouseId', record.data.WarehouseId);
            CaculatorOtherField(Record);
        }
        function NewMasterProcess() {
            DirectMethod.NewDataProcess({
                success: function(resul) {
                    btnNew.setDisabled(true);
                    txtVoucherNo.focus(true, 10);
                }
            });
        }
        /*
        Thuc hien lưu
        */
        function SaveProcess() {
            if (!CheckBeforSave())
                return;
            var JsonDetail = grDetail.store.getChangedData();
            DirectMethod.SaveProcess(JsonDetail, {
                success: function(status) {
                    if (status) {
                        btnNew.setDisabled(false);
                        vnMessageBox('Thông báo !', 'Lưu thành công', Ext.MessageBox.OK, 'txtVoucherNo.focus(true, 10);', Ext.MessageBox.INFO, 1);
                    }
                }
            });
        }

        function CheckBeforSave() {
            var strMesseger = '', fn = '';

            if (txtVoucherNo.getValue() == '') {
                strMesseger += 'Mã phiếu không được trống';
                fn = 'txtVoucherNo.focus(true, 10);';
            }
            else if (dfDocumentDate.getValue() == '') {
                strMesseger += '<br/>Ngày nhập không được trống';
                fn = 'dfDocumentDate.focus(true, 10);';
            }
            var records = grDetail.store.getModifiedRecords();
            if (records.length <= 0 && hdVoucherId.getValue() == '')
                strMesseger += '<br/>nhập chi tiết phiếu trước khi lưu';
            for (var i = 0; i < records.length; i++) {
                if (records[i].data.WarehouseId == '' || records[i].data.UnitId == '' || records[i].data.ProductId == '' || records[i].data.Quantity < 0) {
                    strMesseger += 'Dữ liệu chi tiết chưa hợp lệ vui lòng kiểm tra lại';
                    break;
                }
            }
            if (strMesseger != '') {
                vnMessageBox('Thông báo !', strMesseger, Ext.MessageBox.OK, fn, Ext.MessageBox.INFO, 1);
                return false;
            }
            return true;
        }
        /*
        Tính lại thông tin cho một số 
        */
        function CaculatorOtherField(Records) {
            var Record = Records;
            if (Records == undefined || Records == null)
                Record = grDetail.selModel.selections.items[0];
            if (Record == undefined || Record == null)
                return;
            var UnitPrice = Record.get('UnitPrice');
            var QuanTity = Record.get('Quantity');
            var VATPercent = Record.get('VATPercent');
            var Amount = UnitPrice * QuanTity;
            Record.set('Amount', Amount);
            var VATAmount = VATPercent * Amount * 1.1;
            Record.set('VATAmount', VATAmount);
            var DiscountPercent = Record.get('DiscountPercent');
            var DiscountAmount = (VATAmount + Amount) * DiscountPercent * 1.1
            Record.set('DiscountAmount', DiscountAmount);
            var TotalAmount = (VATAmount + Amount) - DiscountAmount
            Record.set('TotalAmount', TotalAmount);
            Amount = 0, DiscountAmount = 0, VATAmount = 0, TotalAmount;
            var Quantity = 0;
            var items = grDetail.store.data.items;
            for (var i = 0; i < items.length; i++) {
                if (items[i].get('Amount') != null)
                    Amount += items[i].get('Amount');
                if (items[i].get('Quantity') != null)
                    Quantity += items[i].get('Quantity');
                if (items[i].get('DiscountAmount') != null)
                    DiscountAmount += items[i].get('DiscountAmount');
                if (items[i].get('VATAmount') != null)
                    VATAmount += items[i].get('VATAmount');
            }
            dpDiscountAmount.setValue(DiscountAmount);
            dpVATAmount.setValue(VATAmount);
            dpQuantity.setValue(Quantity);
            dpAmount.setValue(Amount);
            dpTotalAmount.setValue(TotalAmount);
        }
        function ComboBoxHide() {

        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager" runat="server" DirectMethodNamespace="DirectMethod">
        <Listeners>
            <DocumentReady Handler="DocumentReady();" />
        </Listeners>
    </ext:ResourceManager>
    <ext:Hidden runat="server" ID="hdVoucherId" Text="">
    </ext:Hidden>
    <ext:Store runat="server" ID="stObject">
        <Reader>
            <ext:JsonReader IDProperty="ObjectId">
                <Fields>
                    <ext:RecordField Name="ObjectId">
                    </ext:RecordField>
                    <ext:RecordField Name="ObjectName">
                    </ext:RecordField>
                    <ext:RecordField Name="TaxCode">
                    </ext:RecordField>
                    <ext:RecordField Name="Address">
                    </ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store runat="server" ID="stInOutMethod">
        <Reader>
            <ext:JsonReader IDProperty="MethodId">
                <Fields>
                    <ext:RecordField Name="MethodId">
                    </ext:RecordField>
                    <ext:RecordField Name="MethodName">
                    </ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store runat="server" ID="stQuotation">
        <Reader>
            <ext:JsonReader IDProperty="QuotationId">
                <Fields>
                    <ext:RecordField Name="QuotationId">
                    </ext:RecordField>
                    <ext:RecordField Name="QuotationNo">
                    </ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store runat="server" ID="stEmployee">
        <Reader>
            <ext:JsonReader IDProperty="EmployeeId">
                <Fields>
                    <ext:RecordField Name="EmployeeId">
                    </ext:RecordField>
                    <ext:RecordField Name="EmployeeName">
                    </ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store runat="server" ID="stCurrency">
        <Reader>
            <ext:JsonReader IDProperty="CurrencyId">
                <Fields>
                    <ext:RecordField Name="CurrencyId">
                    </ext:RecordField>
                    <ext:RecordField Name="CurrencyName">
                    </ext:RecordField>
                    <ext:RecordField Name="Rate">
                    </ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store runat="server" ID="stMaturity">
        <Reader>
            <ext:JsonReader IDProperty="MaturityId">
                <Fields>
                    <ext:RecordField Name="MaturityId">
                    </ext:RecordField>
                    <ext:RecordField Name="MaturityName">
                    </ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store runat="server" ID="stPaymentMethod">
        <Reader>
            <ext:JsonReader IDProperty="PaymentMethodId">
                <Fields>
                    <ext:RecordField Name="PaymentMethodId">
                    </ext:RecordField>
                    <ext:RecordField Name="PaymentMethodName">
                    </ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store runat="server" ID="stUnit">
        <Reader>
            <ext:JsonReader IDProperty="UnitId">
                <Fields>
                    <ext:RecordField Name="UnitId">
                    </ext:RecordField>
                    <ext:RecordField Name="UnitName">
                    </ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store runat="server" ID="stInvoiceType">
        <Reader>
            <ext:JsonReader IDProperty="InvoiceTypeId">
                <Fields>
                    <ext:RecordField Name="InvoiceTypeId">
                    </ext:RecordField>
                    <ext:RecordField Name="InvoiceTypeName">
                    </ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store runat="server" ID="stWareHouse">
        <Reader>
            <ext:JsonReader IDProperty="WarehouseId">
                <Fields>
                    <ext:RecordField Name="WarehouseId">
                    </ext:RecordField>
                    <ext:RecordField Name="WarehouseName">
                    </ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store ID="stDetail" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="VoucherDetailId">
                <Fields>
                    <ext:RecordField Name="VoucherDetailId" UseNull="true" />
                    <ext:RecordField Name="WarehouseId" UseNull="true" />
                    <ext:RecordField Name="ProductId" UseNull="true" />
                    <ext:RecordField Name="ProductCode" UseNull="true" />
                    <ext:RecordField Name="ProductName" UseNull="true" />
                    <ext:RecordField Name="Quantity" UseNull="true" />
                    <ext:RecordField Name="UnitId" UseNull="true" />
                    <ext:RecordField Name="UnitPrice" UseNull="true" />
                    <ext:RecordField Name="VATPercent" UseNull="true" />
                    <ext:RecordField Name="VATAmount" UseNull="true" />
                    <ext:RecordField Name="DiscountPercent" UseNull="true" />
                    <ext:RecordField Name="DiscountAmount" UseNull="true" />
                    <ext:RecordField Name="Amount" UseNull="true" />
                    <ext:RecordField Name="TotalAmount" UseNull="true" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Viewport ID="ViewPort1" runat="server" Layout="RowLayout">
        <Items>
            <ext:Toolbar ID="tbMain" runat="server">
                <Items>
                    <ext:Button runat="server" ID="btnNew" Icon="PageAdd" Text="Tạo mới">
                        <ToolTips>
                            <ext:ToolTip ID="ToolTip9" runat="server" Title="Ctr+N">
                            </ext:ToolTip>
                        </ToolTips>
                        <%--    <Listeners>
                                    <Click Handler="BeforCheckNewClick();" />
                                </Listeners>--%>
                    </ext:Button>
                    <ext:ToolbarSeparator />
                    <ext:Button runat="server" ID="Button1" Text="Lưu" Icon="PageSave">
                    </ext:Button>
                    <ext:ToolbarSeparator />
                    <ext:Button runat="server" ID="Button4" Text="Lưu & Đóng" Icon="PageSave">
                    </ext:Button>
                    <ext:ToolbarSeparator />
                    <ext:Button runat="server" ID="btnUpdate" Text="Sửa" Icon="PageEdit">
                    </ext:Button>
                    <ext:ToolbarSeparator />
                    <ext:Button runat="server" ID="btnDelete" Text="Xóa" Icon="Delete">
                        <ToolTips>
                            <ext:ToolTip ID="ToolTip8" runat="server" Title="Shift+Delete">
                            </ext:ToolTip>
                        </ToolTips>
                        <%--    <Listeners>
                                    <Click Handler="ConfigDeleteObject()" />
                                </Listeners>--%>
                    </ext:Button>
                    <ext:ToolbarSeparator />
                    <ext:Button runat="server" ID="Button5" Text="In phiếu" Icon="PageEdit">
                    </ext:Button>
                </Items>
            </ext:Toolbar>
            <ext:Panel ID="Panel2" runat="server" Frame="true" Height="120" Layout="FormLayout"
                LabelWidth="120">
                <Items>
                    <ext:Panel ID="pnlFlexEven" runat="server" Layout="HBoxLayout" LabelWidth="60" AnchorHorizontal="100%">
                        <Defaults>
                            <ext:Parameter Name="margins" Value="0 5 0 0" Mode="Value" />
                        </Defaults>
                        <LayoutConfig>
                            <ext:HBoxLayoutConfig Padding="2" Align="Middle" />
                        </LayoutConfig>
                        <Items>
                            <ext:TextField ID="txtVoucherNo" runat="server" FieldLabel="Số phiếu" Flex="1" LabelWidth="80"
                                Disabled="true" />
                            <ext:DateField ID="dfVoucherDate" runat="server" FieldLabel="Ngày chứng từ" Flex="1"
                                LabelWidth="90" />
                            <ext:ComboBox ID="cboEmployee" runat="server" TriggerAction="All" FieldLabel="Nhân viên"
                                Flex="1" StoreID="stEmployee" DisplayField="EmployeeName" ValueField="EmployeeId">
                            </ext:ComboBox>
                            <%--<ext:TextField ID="TextField3" runat="server" FieldLabel="Số hóa đơn" Flex="1" LabelWidth="70" />
                            <ext:TextField ID="TextField4" runat="server" FieldLabel="Chứng từ" Flex="1" />--%>
                        </Items>
                    </ext:Panel>
                    <ext:Panel ID="Panel1" runat="server" Layout="HBoxLayout" LabelWidth="70" AnchorHorizontal="100%">
                        <Defaults>
                            <ext:Parameter Name="margins" Value="0 5 0 0" Mode="Value" />
                        </Defaults>
                        <LayoutConfig>
                            <ext:HBoxLayoutConfig Padding="2" Align="Middle" />
                        </LayoutConfig>
                        <Items>
                            <ext:ComboBox ID="cboInputMethod" runat="server" FieldLabel="Phương thức xuất" Flex="1"
                                LabelWidth="110" StoreID="stInOutMethod" DisplayField="MethodName" ValueField="MethodId" />
                            <ext:ComboBox ID="cboPaymentMethod" runat="server" FieldLabel="Phương thức TT" Flex="1"
                                LabelWidth="110" StoreID="stPaymentMethod" DisplayField="PaymentMethodName" ValueField="PaymentMethodId" />
                            <ext:ComboBox ID="cboInvoiceType" runat="server" FieldLabel="Loại hình hóa đơn" Flex="1"
                                LabelWidth="110" StoreID="stInvoiceType" DisplayField="InvoiceTypeName" ValueField="InvoiceTypeId">
                            </ext:ComboBox>
                        </Items>
                    </ext:Panel>
                    <ext:Panel ID="Panel3" runat="server" Layout="HBoxLayout" LabelWidth="70" AnchorHorizontal="100%">
                        <Defaults>
                            <ext:Parameter Name="margins" Value="0 5 0 0" Mode="Value" />
                        </Defaults>
                        <LayoutConfig>
                            <ext:HBoxLayoutConfig Padding="2" Align="Middle" />
                        </LayoutConfig>
                        <Items>
                            <ext:ComboBox ID="cboObject" FieldLabel="Khách hàng" runat="server" TriggerAction="All"
                                Flex="2" LabelWidth="80" StoreID="stObject" DisplayField="ObjectName" ValueField="ObjectId">
                                <Listeners>
                                    <Select Fn="Customer_Change" />
                                </Listeners>
                            </ext:ComboBox>
                            <ext:Button ID="Button2" runat="server" Icon="Add" Flat="true" />
                            <ext:TextField ID="txtTaxCode" runat="server" FieldLabel="MST" Flex="1" Disabled="true"
                                LabelWidth="40" />
                            <ext:TextField ID="txtAddress" runat="server" FieldLabel="Địa chỉ" AnchorHorizontal="100%"
                                Flex="3" LabelWidth="50" Disabled="true" />
                        </Items>
                    </ext:Panel>
                    <%-- <ext:Panel ID="Panel5" runat="server" Layout="HBoxLayout" LabelWidth="60" AnchorHorizontal="100%">
                        <Defaults>
                            <ext:Parameter Name="margins" Value="0 5 0 0" Mode="Value" />
                        </Defaults>
                        <LayoutConfig>
                            <ext:HBoxLayoutConfig Padding="2" Align="Middle" />
                        </LayoutConfig>
                        <Items>
                        </Items>
                    </ext:Panel>--%>
                    <%-- <ext:Panel ID="Panel4" runat="server" Layout="HBoxLayout" LabelWidth="60" AnchorHorizontal="100%">
                        <Defaults>
                            <ext:Parameter Name="margins" Value="0 5 0 0" Mode="Value" />
                        </Defaults>
                        <LayoutConfig>
                            <ext:HBoxLayoutConfig Padding="2" Align="Middle" />
                        </LayoutConfig>
                        <Items>
                        </Items>
                    </ext:Panel>--%>
                    <ext:Panel ID="Panel6" runat="server" Layout="HBoxLayout" LabelWidth="120" AnchorHorizontal="100%">
                        <Defaults>
                            <ext:Parameter Name="margins" Value="0 5 0 0" Mode="Value" />
                        </Defaults>
                        <LayoutConfig>
                            <ext:HBoxLayoutConfig Padding="2" Align="Middle" />
                        </LayoutConfig>
                        <Items>
                            <ext:ComboBox ID="cboQuotation" runat="server" Editable="false" FieldLabel="Báo giá"
                                Flex="1" StoreID="stQuotation" DisplayField="QuotationNo" ValueField="QuotationId"
                                LabelWidth="80" />
                            <ext:ComboBox runat="server" ID="cboWarehouse" ValueField="WarehouseId" DisplayField="WarehouseName"
                                TriggerAction="All" EnableKeyEvents="true" FireSelectOnLoad="true" FieldLabel="Kho xuất"
                                StoreID="stWareHouse" LabelWidth="80" Flex="1">
                            </ext:ComboBox>
                            <ext:ComboBox ID="cboMaturity" runat="server" Editable="false" FieldLabel="Thời hạn thanh toán"
                                Flex="1" StoreID="stMaturity" DisplayField="MaturityName" ValueField="MaturityId">
                            </ext:ComboBox>
                            <ext:Button ID="Button3" runat="server" Icon="Add" Flat="true" />
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:Panel>
            <ext:GridPanel ID="grDetail" runat="server" AutoExpandColumn="ProductName" Border="false"
                RowHeight="1" ColumnLines="true" StoreID="stDetail">
                <ColumnModel ID="ColumnModel2" runat="server">
                    <Columns>
                        <ext:Column ColumnID="ProductName" DataIndex="ProductName" Header="Mặt hàng" Width="200">
                            <Editor>
                                <ext:ComboBox ID="ComboBox1" runat="server" DisplayField="ProductName" ValueField="ProductName"
                                    TypeAhead="true" LoadingText="Tìm kiếm..." ItemSelector="div.search-item" TriggerAction="All"
                                    MinChars="1" HideTrigger="true">
                                    <Listeners>
                                        <Select Fn="SelectItem" />
                                    </Listeners>
                                    <Store>
                                        <ext:Store ID="Store1" runat="server" AutoLoad="false">
                                            <Proxy>
                                                <ext:HttpProxy Method="POST" Url="../List/SearProduct.ashx" DisableCaching="true" />
                                            </Proxy>
                                            <Reader>
                                                <ext:JsonReader Root="SearProduct" TotalProperty="total">
                                                    <Fields>
                                                        <ext:RecordField Name="ProductId" />
                                                        <ext:RecordField Name="ProductCode" />
                                                        <ext:RecordField Name="InputPrice" />
                                                        <ext:RecordField Name="InputUnit" />
                                                        <ext:RecordField Name="ProductName" />
                                                        <ext:RecordField Name="WarehouseId" />
                                                    </Fields>
                                                </ext:JsonReader>
                                            </Reader>
                                        </ext:Store>
                                    </Store>
                                    <Template ID="Template1" runat="server">
                                        <Html>
                                        <tpl for=".">                                        
						                  <div class="search-item">
							                 <h3><span>{ProductCode}</span>{ProductName}</h3>
						                  </div>
					                   </tpl>
                                        </Html>
                                    </Template>
                                </ext:ComboBox>
                            </Editor>
                        </ext:Column>
                        <%--  <ext:Column ColumnID="clWarehouse" DataIndex="WarehouseId" Header="Kho hàng">
                            <Renderer Handler="return Render(value,'stWareHouse','WarehouseName');" />
                            <Editor>
                                <ext:ComboBox runat="server" ID="cbWarehouse" ValueField="WarehouseId" DisplayField="WarehouseName"
                                    TriggerAction="All" EnableKeyEvents="true" FireSelectOnLoad="true">
                                    <Store>
                                        <ext:Store runat="server" ID="stWareHouse">
                                            <Reader>
                                                <ext:JsonReader IDProperty="WarehouseId">
                                                    <Fields>
                                                        <ext:RecordField Name="WarehouseId">
                                                        </ext:RecordField>
                                                        <ext:RecordField Name="WarehouseName">
                                                        </ext:RecordField>
                                                    </Fields>
                                                </ext:JsonReader>
                                            </Reader>
                                        </ext:Store>
                                    </Store>
                                    
                                </ext:ComboBox>
                            </Editor>
                        </ext:Column>--%>
                        <ext:Column DataIndex="UnitId" Header="ĐVT">
                            <Renderer Handler="return Render(value,'stUnit','UnitName');" />
                            <Editor>
                                <ext:ComboBox runat="server" ID="cbUnit" StoreID="stUnit" TriggerAction="All" DisplayField="UnitName"
                                    ValueField="UnitId">
                                </ext:ComboBox>
                            </Editor>
                        </ext:Column>
                        <ext:Column DataIndex="Quantity" Header="Số lượng" Align="Right">
                            <EditorOptions CancelOnEsc="true">
                                <Listeners>
                                    <Complete Handler="CaculatorOtherField(editor.record)" />
                                </Listeners>
                            </EditorOptions>
                            <Editor>
                                <ext:NumberField ID="txtQuantity" runat="server" MinValue="1" MaxLengthText="18"
                                    SelectOnFocus="true">
                                </ext:NumberField>
                            </Editor>
                        </ext:Column>
                        <ext:Column DataIndex="UnitPrice" Header="Đơn giá" Align="Right">
                        </ext:Column>
                        <ext:Column DataIndex="Amount" Header="Thành tiền" Align="Right" />
                        <ext:Column DataIndex="VATPercent" Header="% VAT" Align="Right">
                            <EditorOptions CancelOnEsc="true">
                                <Listeners>
                                    <Complete Handler="CaculatorOtherField(editor.record)" />
                                </Listeners>
                            </EditorOptions>
                            <Editor>
                                <ext:NumberField ID="NumberField3" runat="server" MinValue="0" MaxLengthText="18"
                                    SelectOnFocus="true">
                                </ext:NumberField>
                            </Editor>
                        </ext:Column>
                        <ext:Column DataIndex="VATAmount" Header="Tiền VAT" Hidden="true" Align="Right">
                        </ext:Column>
                        <ext:Column DataIndex="DiscountPercent" Header="% Chiết khấu" Align="Right">
                            <EditorOptions CancelOnEsc="true">
                                <Listeners>
                                    <Complete Handler="CaculatorOtherField(editor.record)" />
                                </Listeners>
                            </EditorOptions>
                            <Editor>
                                <ext:NumberField ID="NumberField4" runat="server" MinValue="0" MaxLengthText="18"
                                    SelectOnFocus="true">
                                </ext:NumberField>
                            </Editor>
                        </ext:Column>
                        <ext:Column DataIndex="DiscountAmount" Header="Tiền Chiết khấu" Hidden="true" Align="Right" />
                        <ext:Column DataIndex="TotalAmount" Header="Tổng tiền" Align="Right" />
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel SingleSelect="true" MoveEditorOnEnter="false">
                        <Listeners>
                            <RowSelect Fn="GridRowSelect" Delay="100" />
                        </Listeners>
                    </ext:RowSelectionModel>
                </SelectionModel>
                <Listeners>
                    <ColumnResize Handler="updateTotal(#{grDetail});" Delay="5" />
                    <AfterRender Handler="updateTotal(#{grDetail});" Delay="5" />
                    <BeforeEdit Fn="BeforeEdit" />
                </Listeners>
                <View>
                    <ext:GridView MarkDirty="false" />
                </View>
                <BottomBar>
                    <ext:Toolbar ID="Toolbar2" runat="server">
                        <Items>
                            <ext:DisplayField ID="DisplayField3" runat="server" DataIndex="ProductName" Text=" " />
                            <ext:DisplayField ID="DisplayField2" runat="server" DataIndex="WarehouseId" Text=" " />
                            <ext:DisplayField ID="dpQuantity" runat="server" DataIndex="Quantity" Cls="total-field"
                                Text="0" />
                            <ext:DisplayField ID="DisplayField4" runat="server" DataIndex="UnitId" Text=" " />
                            <ext:DisplayField ID="DisplayField1" runat="server" DataIndex="UnitPrice" Text=" " />
                            <ext:DisplayField ID="dpAmount" runat="server" DataIndex="Amount" Cls="total-field"
                                Text="0" />
                            <ext:DisplayField ID="DisplayField5" runat="server" DataIndex="VATPercent" Text=" " />
                            <ext:DisplayField ID="dpVATAmount" runat="server" DataIndex="VATAmount" Cls="total-field"
                                Text="0" />
                            <ext:DisplayField ID="DisplayField6" runat="server" DataIndex="DiscountPercent" Text=" " />
                            <ext:DisplayField ID="dpDiscountAmount" runat="server" DataIndex="DiscountAmount"
                                Cls="total-field" Text="0" />
                            <ext:DisplayField ID="dpTotalAmount" runat="server" DataIndex="TotalAmount" Cls="total-field"
                                Text="0" />
                        </Items>
                    </ext:Toolbar>
                </BottomBar>
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
    </form>
</body>
</html>
